Page({
  data: {
    loading: true,
    option1: [
        { text: '所有时间', value: 0 },
        { text: '一周内', value: 1 },
        { text: '半个月内', value: 2 },
        { text: '半年内', value: 3 },
      ],
      option2: [
        { text: '所有问卷', value: 'a' },
        { text: '进行中', value: 'b' },
        { text: '已完成', value: 'c' },
      ],
      value1: 0,
      value2: 'a',
      surveys: [],
      surveyname: '',
      startTime: '' 
  },
  onLoad: function () {
      this.refreshmethod(true)
      var timeout1 =  setTimeout(()=>{
        this.setData({
          loading: false
        })
      },500)
  },
  onPullDownRefresh: function () {
      this.refreshmethod(false)
  },

  refreshmethod: function (load) {
    wx.showNavigationBarLoading()
    wx.cloud.callFunction({
        name: 'getSurveys',
        data:{
            surveyname:this.data.surveyname,
            startTime: this.data.startTime
        }
    }).then(res =>{
      // console.log(res)
      this.setData({
          surveys : res.result.data
      })
      wx.hideNavigationBarLoading()
      if (load == false)
      wx.stopPullDownRefresh()
    })
  },

//    跳转到新建问卷页面
  toEdit(){
    wx.navigateTo({
      url: "/pages/newquestionnaire/newquestionnaire",
    })
  },

  // 搜索框中点击搜索或者回车触发   
  changeSearch(e){
      this.setData({
          surveyname : e.detail
      })
      this.refreshmethod(false)
  },

// 更改时间时触发   
  timeChange(e){
    console.log(e.detail)
  },
  typeChange(e){
    console.log(e.detail)
  },

  onUnload(){
    // 清除定时器
    clearTimeout(timeout1)
  }
})


